﻿@model SuCasa.Models.MemberSearchViewModel

<div id="results">
    @if (Model.SearchResults != null)
    {
        <table class="table table-striped">
            <thead>
                <tr>
                    <th></th>
                    <th>
                        Name
                    </th>
                    <th>
                        Address
                    </th>
                    <th>
                        Home Phone
                    </th>
                    <th>
                        Cell Phone
                    </th>
                    <th>
                        Email
                    </th>
                </tr>
            </thead>
            <tbody>

                @foreach (var item in Model.SearchResults)
                {
                    <tr>
                        <td>
                            @Html.ActionLink("Edit", "Edit", new { id=item.MemberId }) ||
                            @Html.ActionLink("Details", "Details", new { id=item.MemberId }) ||
                            @Html.ActionLink("Call Log", "Add", "CallLog", new { id=item.MemberId }, null) ||
                            @*@using (Ajax.BeginForm("Search", "Member", new AjaxOptions { UpdateTargetId = "results", HttpMethod = "GET", }, new { @class = "form-horizontal" })){
                                <input type="hidden" name="id" value="@item.MemberId"/>
                                <a class="deleteButton" href="#" >Delete</a>
                            }*@
                            <a href="#" onclick="deleteMember(@(item.MemberId))">Delete</a>
                        </td>
                        <td>
                            @item.Name
                        </td>
                        <td>
                            @item.Address
                        </td>
                        <td>
                            @item.HomePhone
                        </td>
                        <td>
                            @item.CellPhone
                        </td>
                        <td>
                            @item.Email
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    }
</div>

<script type="text/javascript">
    $(function () {
        $('.deleteButton').click(function () {
            $(this).closest('form').submit();
        });
    });
    var path = '@Url.Action("Delete", "Member")';
    function deleteMember(memberId) {
        $.ajax({
            type: "GET",
            url: path,
            data: { 'id': memberId },
            dataType: 'json',
            contentType: 'application/json',
            success: function () {
                window.location.reload();
            }
        });
        return false;
    }
</script>